package com.controller;

import com.entity.Course;
import com.entity.CourseType;
import com.service.CourseService;
import com.service.CourseTypeService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

@Controller
@RequestMapping("/ct")
public class UserCourseTypeController {
    //====张
    @Autowired
    CourseTypeService courseTypeService;
    @Autowired
    CourseService courseService;

    @RequestMapping("/findCourseType.do")
    @ResponseBody
    public Map findCourseType() {
        List<CourseType> courseTypes = courseTypeService.findCourseTypes();
        List<Course> courses = courseService.findTopByGroup();
        Map map = new HashMap();
        map.put("courseTypes", courseTypes);
        map.put("courseService", courseService);
        return map;
    }
    @RequestMapping("/findByParentId.do")
    @ResponseBody
    public List<List<CourseType>> findByParentId(int parent_id){
        List<List<CourseType>> list = new ArrayList<>();
        List<CourseType> types=courseTypeService.findByParentId(parent_id);
        for (CourseType type: types){
            list.add(courseTypeService.findByParentId(type.getId()));
        }
        return list;
    }
//====张
}
